package com.epro.dx.util;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

/**
 * map工具类
 * @author  qsc255
 * @version  [版本号, 2015-3-10]
 * @see  [相关类/方法]
 * @since  [产品/模块版本]
 */
public class MapUtil
{
    /**
     *
     * 通过map的value值获取key值
     * @param map
     * @param value
     * @return  [参数说明]
     * @return List [返回类型说明]
     * @exception throws [违例类型] [违例说明]
     * @see [类、类#方法、类#成员]
     */
    public static List getKeyByValue(Map map, Object value)
    {
        List keys = new ArrayList();
        Iterator it = map.entrySet().iterator();
        while (it.hasNext())
        {
            Map.Entry entry = (Entry)it.next();
            Object obj = entry.getValue();
            if (obj != null && obj.equals(value))
            {
                keys.add(entry.getKey());
            }

        }
        Collections.sort(keys);
        return keys;
    }

    /**
     *
     * 遍历map中所有的value
     * @param map
     * @return  [参数说明]
     * @return List [返回类型说明]
     * @exception throws [违例类型] [违例说明]
     * @see [类、类#方法、类#成员]
     */
    public static List getValues(Map map)
    {
        Iterator it = map.entrySet().iterator();
        List list = new ArrayList();
        while (it.hasNext())
        {
            Map.Entry entry = (Map.Entry)it.next();
            Object value = entry.getValue();
            list.add(value.toString());
        }
        Collections.sort(list);
        return list;
    }
}
